<?php
//
//	file: includes/aucp/rank_plugs.php
//	begin: 09/05/2007
//	$Author: christopher $
//	$Revision: 29 $
//	$Date: 2008-07-19 15:59:35 +0000 (Sat, 19 Jul 2008) $
//	license: http://opensource.org/licenses/gpl-license.php GNU General Public License (GPL)
//
//	description: rank plugs

if ( !defined('IN_PHPBB') )
{
	die('Hacking attempt');
	exit;
}

class rank_plugs extends plug_ins
{
	var $posts;
	var $mode;

	function rank_plugs()
	{
		global $config;

		$this->posts = false;
		$this->mode = $config->data['aucp_rank_mode'];
	}
}

class rank_topic extends plug_ins
{
	function start()
	{
		global $user;

		$user->pool_fields[] = 'user_custom_rank';
	}
}

class rank_posts extends rank_plugs
{
	var $posts;
	var $mode;

	function rank_plug_posts()
	{
		parent::rank_plugs();
	}

	function set_posts(&$posts)
	{
		$this->posts = &$posts;
	}

	function display($post_id=0, $tpl_switch='')
	{
		global $user, $template;

		if(!$post_id)
		{
			return;
		}

		// first, we get data for the specific row
		$postrow = $this->posts->data[intval($post_id)];
		$poster_id = isset($user->pool[ $postrow['poster_id'] ]) ? $postrow['poster_id'] : ANONYMOUS;
		$rank = $this->posts->get_rank($poster_id);

		// then, we play with the poster block for that user
		if ( !empty($user->pool[$poster_id]['user_custom_rank']) )
		{
			$tpl_data = array();
			$custom_rank = _htmldecode($user->pool[$poster_id]['user_custom_rank']);
			switch( $this->mode )
			{
				case CUSTOM_RANK_MODE_REPLACE_BOTH:
					$tpl_data['I_POSTER_RANK'] = '';
				case CUSTOM_RANK_MODE_REPLACE_RANK:
					$tpl_data['L_POSTER_RANK'] = $custom_rank;
					break;
				case CUSTOM_RANK_MODE_INDEPENDENT:
					$tpl_data['L_POSTER_RANK'] = '<strong>' . $custom_rank . '</strong><br />' . $rank['txt'];
					break;
				default:
					break;
			}
			if ( empty($tpl_switch) )
			{
				$template->assign_vars($tpl_data);
			}
			else
			{
				$template->assign_lastblock_vars($tpl_switch, $tpl_data);
			}
		}

		return;
	}
}

class rank_profile extends rank_plugs
{
	var $posts;
	var $mode;

	function rank_plug_profile()
	{
		parent::rank_plugs();
	}

	function view()
	{
		global $config, $template, $profiledata, $tpl_vars;

		$poster_rank = !isset($tpl_vars['L_POSTER_RANK']) || empty($tpl_vars['L_POSTER_RANK']) ? '' : $tpl_vars['L_POSTER_RANK'];
		$rank_image = !isset($tpl_vars['I_POSTER_RANK']) || empty($tpl_vars['I_POSTER_RANK']) ? '' : $template->sprintf('<img src="%s" alt="" rank="%s" border="0" />', $tpl_vars['I_POSTER_RANK'], $poster_rank);
		$custom_rank = _htmldecode($user->pool[$poster_id]['user_custom_rank']);

		if ( !empty($profiledata['user_custom_rank']) )
		{
			switch( $this->mode )
			{
				case CUSTOM_RANK_MODE_REPLACE_BOTH:
					$rank_image = '';
				case CUSTOM_RANK_MODE_REPLACE_RANK:
					$poster_rank = $custom_rank;
					break;
				case CUSTOM_RANK_MODE_INDEPENDENT:
					$poster_rank = '<strong>' . $custom_rank . '</strong><br />' . $poster_rank;
					break;
				default:
					break;
			}
		}

		$template->assign_vars(array(
			'POSTER_RANK' => $poster_rank,
			'RANK_IMAGE' => $rank_image,
		));

		return;
	}
}
?>